#pragma once

#include <iostream>
#include <stdarg.h>
#include <ctime>

#define INFO 1
#define ERROR 2
#define DEBUG 3
#define WARNING 4
#define FATAL 5

const char* level_name[] = {
    "INFO",
    "ERROR",
    "DEBUG",
    "WARNING",
    "FATAL"
};

void log(int level, const char* format, ...)
{
    time_t tm = time(nullptr);
    struct tm* curTime = localtime(&tm);
    char inbuffer[256];
    snprintf(inbuffer, sizeof(inbuffer), "[%s][%d/%d/%d %d:%d:%d]", level_name[level - 1], curTime->tm_year + 1900, \
                curTime->tm_mon + 1, curTime->tm_yday, curTime->tm_hour, curTime->tm_min, curTime->tm_sec);

    va_list s;
    va_start(s, format);
    char infobuffer[256];
    vsnprintf(infobuffer, sizeof(infobuffer), format, s);
    va_end(s);

    char buffer[512];
    snprintf(buffer, sizeof(buffer), "%s %s", inbuffer, infobuffer);
    printf("%s\n", buffer);
}